package leetcode.code1608;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int specialArray(int[] nums) {
		Arrays.sort(nums);
		int len = nums.length;
		for (int i = 0; i < nums.length; i++) {
			if (len - i <= nums[i] && (i == 0 || nums[i - 1] < len - i)) {
				return len - i;
			}
		}
		return -1;
	}

	@Override
	public void debug4() {
		H.compare(2, this.specialArray(H.str2array3("[3,5]")));
		H.compare(-1, this.specialArray(H.str2array3("[0,0]")));
		H.compare(3, this.specialArray(H.str2array3("[0,4,3,0,4]")));
		H.compare(-1, this.specialArray(H.str2array3("[3,6,7,7,0]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
